package com.dbq.fast.business.main.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dbq.fast.R;

/**
 * Created by yuanchen on 2018/4/17.
 */

public class TimeWight extends LinearLayout {

    TextView time1TV;
    TextView time2TV;
    TextView time3TV;
    TextView time4TV;

    public TimeWight(Context context) {
        this(context, null);
    }

    public TimeWight(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TimeWight(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public void updateTime(String time) {
        if(time == null || time.length() < 5) return;

        time1TV.setText(time.substring(0, 1));
        time2TV.setText(time.substring(1, 2));
        time3TV.setText(time.substring(3, 4));
        time4TV.setText(time.substring(4, 5));
    }

    private void initView(Context context) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.time_widgt, null);
        time1TV = rootView.findViewById(R.id.time_1);
        time2TV = rootView.findViewById(R.id.time_2);
        time3TV = rootView.findViewById(R.id.time_3);
        time4TV = rootView.findViewById(R.id.time_4);

        addView(rootView);
    }


}
